package com.example.homework2.controller;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Random;

@Controller
public class taskController {

        @RequestMapping({ "/random"})
        public String random(Model model){
            Random random = new Random();
            int randomNumber = random.nextInt(1000);
            model.addAttribute("randomNumber", randomNumber);
            return  "random"; // assuming the name of your template is "random.html"
        }

        @RequestMapping("/square/{n}")
        public ModelAndView square(@PathVariable int n){
            int square = n * n;
            ModelAndView modelAndView = new ModelAndView("square");
            modelAndView.addObject("message", "the square of "+ n + " is: "+ square);
            return modelAndView;
        }


}
